<template>
  <el-dialog :append-to-body="true" :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="800px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <!-- <el-row>
        <el-col :span="12">
          <el-form-item label="项目类型" prop="projecttype">
            <el-input v-model="model.projecttype" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="项目等级" prop="projectlevel">
            <el-input v-model="model.projectlevel" :disabled="true"></el-input>
          </el-form-item>
        </el-col>
      </el-row> -->
      <el-row>
        <!-- <el-col :span="12">
          <el-form-item label="模板里程碑及任务id" prop="mileposttemplateid">
            <el-input v-model="model.mileposttemplateid" :disabled="true"></el-input>
          </el-form-item>
        </el-col> -->
        <!-- <el-col :span="12">
          <el-form-item label="模板里程碑及任务名称" prop="mileposttemplatename">
            <el-input v-model="model.mileposttemplatename" :disabled="true"></el-input>
          </el-form-item>
        </el-col> -->
        <el-col :span="12">
          <el-form-item label="任务名称" prop="taskname" :rules="rules.validateRequire">
            <el-input v-model="model.taskname"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="序号" prop="sortcode" :rules="rules.validateRequire">
            <el-input v-model="model.sortcode"></el-input>
          </el-form-item>
        </el-col>
        <!-- <el-col :span="12">
          <el-form-item label="任务类型" prop="tasktype" :rules="rules.validateRequire">
            <el-select v-model="model.tasktype" filterable clearable>
              <el-option v-for="item in codeModel.tasktypeList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="12">
          <el-form-item label="优先级" prop="taskpriority" :rules="rules.validateRequire">
            <el-select v-model="model.taskpriority" filterable clearable>
              <el-option v-for="item in codeModel.taskpriorityList" :key="item.code" :label="item.name" :value="item.code" />
            </el-select>
          </el-form-item>
        </el-col> -->
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="任务内容" prop="taskdetail">
            <el-input v-model="model.taskdetail" maxlength="1000" show-word-limit type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <el-form-item label="任务说明" prop="taskexplain">
            <el-input v-model="model.taskexplain" maxlength="1000" show-word-limit type="textarea" :rows="4"></el-input>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: {},
  data() {
    return {
      moduleTitle: '任务模板',
      urlPrefix: '/mpm/projectTaskTemplate/',
      url: {
        // 额外的url
      }
    }
  },
  props: {
    parentId: {
      type: [Number, String],
      required: true
    },
    mileposttemplate: {
      type: [String],
      required: true
    }
  },
  methods: {
    open() {
      this.model = {}
      this.$nextTick(() => {
        this.$refs.form.clearValidate()
        if (this.isAdd === true) {
          this.title = '添加' + this.moduleTitle
          // 需要添加重复判断
          if (this.$store.getters.param.isAvoidRepeat === true) {
            this.queryBillUid()
          }
          if (this.isQueryInitData === true) {
            // 后台进行数据初始化
            this.queryInitData().then(_ => {
              this.assignDefaultValue()
              this.loaded()
            })
          } else {
            // 前台进行数据初始化，不初始化sortcode的值为0
            this.$set(this.model, 'enabled', 1)
            this.assignDefaultValue()
            this.loaded()
          }
        } else if (this.disableEditSubmit === false) {
          this.title = '编辑' + this.moduleTitle
          this.queryData(this.id).then(_ => {
            this.loaded()
          })
        } else {
          this.title = '查看' + this.moduleTitle
          this.queryData(this.id).then(_ => {
            this.loaded()
          })
        }
      })
    },
    assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'mileposttemplateid', this.parentId)
        this.$set(this.model, 'mileposttemplatename', this.mileposttemplate)
      }
    },
    loaded() {
      // 页面加载完毕执行

    }
  }
}
</script>

